<!--Generate by Kevin's CodeBuilder -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
		<meta charset="UTF-8">
		<title>bui-ssm快速开发框架</title>
		<head th:include="source::header"></head>
		<style type="text/css">
			#form_main_wrap{
				padding:12px;
			}
		</style>
</head>
<body>
		<div id="form_main_wrap" class="form_main_wrap">
			<div id="roleswrap">
			
			</div>
		</div>
</div>
<script type="application/javascript" th:inline="javascript">
	var userRoles = [(${userRoles})],
		rolesJson = [(${rolesJson})],
		userId = '[(${userId})]';
	
	$(function(){
		var wrap = $("#roleswrap");
		for(var i = 0, len = rolesJson.length ; i < len ;++i){
			var role = rolesJson[i];
			var checked = "";
			for(var j = 0 ,jlen = userRoles.length ; j < jlen ;++j){
				if(userRoles[j].roleId === role.id){
					checked = 'checked="checked"';
					break;
				}	
			}			
			wrap.append('<label class="k_checkbox_label k_checkbox_anim">'
                        +'<input type="checkbox" '+checked+' name="hobby" value="'+role.id+'" /><i class="k_checkbox_i"></i>'+role.roleName+'</label>');
		}
		//保存
		parent.saveUserRoleFn = function($win,btn){
			var roleIds = [];
			wrap.find("input[type=checkbox]").each(function(){
				var $t = $(this);
				if($t.prop("checked")){
					roleIds.push($t.val());
				}
			});
			var rolesId = roleIds.join(",");
			$B.changeButtonStatus(btn);
			$B.request({
				data:{userId:userId,roleIds:rolesId},
				url:$B.getHttpHost(ctxPath)+"user/roleUpdate",
				ok:function(){
					$B.success({
						message:'[(${Lang.common_saveSucess})]',
						timeout:1.5,
						onClosed:function(){
							parent.saveUserRoleFn = undefined;
							$win.close();
						}
					});					
				},
				final:function(){
					$B.changeButtonStatus(btn);
				}
			});			
			
		};
		
	});
	
</script>
</body>
</html>